var str = '2018-05-03 '.trim()
var reg = /^(\d{4})-(\d{2})-(\d{2})$/;
console.log(str.match(reg))

